<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <ui:composition template="/resources/templates/default.xhtml">
        <ui:define name="title">Etudiants et machines</ui:define>
        <ui:define name="titlePage">Liste des étudiants et machines</ui:define>
        <ui:define name="content"> 
                <h:form id="formGestionEleve">

                    <p:dataTable value="#{administrationBean.etudiants}" var="etu"  rowKey="#{etu.idPersonne}" paginator="true" rows="25"  
                                  id="tabEtudiant" rowsPerPageTemplate="10,15,20,25,50,100" sortMode="multiple" filteredValue="#{administrationBean.listePromotionFilter}"
                                  selection="#{administrationBean.selectedEtudiant}">

                        <p:column style="width:16px">  
                            <p:rowToggler />  
                        </p:column>  

                        <p:column headerText="Nom" sortBy="#{etu.nom}" filterBy="#{etu.nom}">  
                            #{etu.nom}  
                        </p:column>  

                        <p:column headerText="Prenom" sortBy="#{etu.prenom}" filterBy="#{etu.prenom}" >  
                            #{etu.prenom}  
                        </p:column>  

                        <p:column headerText="Promotion" filterOptions="#{administrationBean.listeChoixPromotion}" filterBy="#{etu.promotion.libelle}" filterMatchMode="exact" >  
                            #{etu.promotion.libelle}  
                        </p:column>

                        <p:column headerText="Action" style="width: 88px">
                            <p:commandButton id="bModifEtudiant" actionListener="#{administrationBean.selectedEtudiant(etu)}" icon="ui-icon-pencil"
                                             update=":formDialog" oncomplete="PF('etudiantDialog').show()" />
                            
                        </p:column>
                        <p:column  style="width: 12%;text-align: center;" headerText="Suppression" selectionMode="multiple"  >
                            <f:facet name="footer" >  
                                <p:commandButton value="Supprimer la sélection" oncomplete="PF('etudiantDeleteDialog').show()" 
                                                 update=":formDeleteEtudiant" style="float:right; font-size: 10px;">  
                                    <p:confirm header="Confirmation" message="Etes vous sur de vouloir supprimer ces Etudiants?" icon="ui-icon-alert" />  
                                </p:commandButton>  
                            </f:facet>
                        </p:column>

                        <p:rowExpansion id="roxexp">
                            <p:dataTable value="#{etu.listeMachines}" var="machine" >
                                <p:column headerText="IP" >  
                                    #{machine.ip}  
                                </p:column>  
                                <p:column headerText="Libelle" >  
                                    #{machine.libelle}  
                                </p:column>  
                                <p:column headerText="MAC" >  
                                    #{machine.adresseMAC}  
                                </p:column>  
                                <p:column headerText="Type" >  
                                    #{machine.typeMachine.libelle}  
                                </p:column>
                                <p:column headerText="Delete" >  
                                    <p:commandButton value="DEL" actionListener="#{administrationBean.selectedMachine(machine)}" icon="ui-icon-trash"
                                                     update=":formDeleteMachineDialog" oncomplete="PF('machineDeleteDialog').show()"/>
                                </p:column>
                            </p:dataTable>
                        </p:rowExpansion>
                    </p:dataTable>
                </h:form>
        </ui:define>
        <ui:define name="dialogs">
            <p:confirmDialog widgetVar="confirmDial" global="true" showEffect="fade" hideEffect="explode">  
                <h:form>
                    <p:commandButton value="Oui" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>  
                    <p:commandButton value="Non" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>    
                </h:form>
            </p:confirmDialog>  
            
            <p:dialog id="dialogSuppEtu" header="Les étudiants suivants on été supprimés"
                      widgetVar="etudiantDeleteDialog" resizable="false" showEffect="clip" hideEffect="puff">
                <h:form id="formDeleteEtudiant">
                    <p:dataList  id="displayMulti" value="#{administrationBean.selectedEtudiant}" var="selectedEtu">  
                        <p:outputLabel value="Etu: #{selectedEtu.nom}" />
                            #{administrationBean.deleteEtudiant(selectedEtu)}
                    </p:dataList> 

                    <h:panelGrid columns="2">
                        <p:commandButton value="OK" oncomplete="PF('etudiantDeleteDialog').hide()"
                                         update=":growl :formGestionEleve"/>
                    </h:panelGrid>
                </h:form>
            </p:dialog>


            <p:dialog id="dialogSuppMach" header="Supprimer #{administrationBean.machine.libelle} ?"
                      widgetVar="machineDeleteDialog" resizable="false" showEffect="clip" hideEffect="puff" modal="true" closable="false">
                <h:form id="formDeleteMachineDialog">
                    <p:inputText value="#{administrationBean.machine.idMachine}" style="display: none"/>
                    <h:panelGrid columns="2">
                        <p:commandButton value="OUI" action="#{administrationBean.deleteMachine()}" update=":growl :formGestionEleve" 
                                         oncomplete="PF('machineDeleteDialog').hide()"/>
                        <p:commandButton value="NON"  oncomplete="PF('machineDeleteDialog').hide()"/>
                    </h:panelGrid>
                </h:form>
            </p:dialog>

            <p:dialog id="dialog" header="#{administrationBean.etudiant.nom} #{administrationBean.etudiant.prenom} - #{administrationBean.etudiant.promotion.libelle}"
                      widgetVar="etudiantDialog" resizable="false" height="400" width="900" showEffect="clip" hideEffect="puff" modal="true">
                <h:form id="formDialog">
                    <p:inputText value="#{administrationBean.etudiant.idPersonne}" style="display: none"/>
                    <h:panelGrid columns="2">
                        <p:outputLabel value="Nom"/>
                        <p:inputText value="#{administrationBean.etudiant.nom}"/>
                        <p:outputLabel value="Prenom"/>
                        <p:inputText value="#{administrationBean.etudiant.prenom}"/>
                        <p:outputLabel value="Promotion"/>
                        <p:selectOneMenu value="#{administrationBean.etudiant.promotion.idPromotion}">
                            <f:selectItems value="#{administrationBean.promotions}" var="p" itemLabel="#{p.libelle}" itemValue="#{p.idPromotion}"/>
                        </p:selectOneMenu>
                        <p:outputLabel value="Login"/>
                        <p:inputText value="#{administrationBean.etudiant.login}"/>
                        <p:outputLabel value="Password"/>
                        <p:inputText value="#{administrationBean.etudiant.password}"/>
                        <p:commandButton value="Modifier" actionListener="#{administrationBean.modifierEtudiant()}" update=":growl :formGestionEleve" oncomplete="PF('etudiantDialog').hide()"/>
                    </h:panelGrid>
                </h:form>
            </p:dialog>
        </ui:define>
    </ui:composition>
</html>
